package demoMod.nanaki.patches.events.city;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.events.shrines.Nloth;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.tempCards.UnselfishDevotion;
import demoMod.nanaki.characters.NanakiCharacter;

public class NlothPatch {
    public static final String ID = NanakiMod.makeID("N'loth");
    private static final EventStrings eventStrings;
    public static final String NAME;
    public static final String[] DESCRIPTIONS;
    public static final String[] OPTIONS;

    @SpirePatch(
            clz = Nloth.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(Nloth event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int maxHpToLose = (int) ((AbstractDungeon.ascensionLevel >= 15 ? 0.15F : 0.1F) * AbstractDungeon.player.maxHealth);
                event.imageEventText.setDialogOption(String.format(OPTIONS[3], maxHpToLose), new UnselfishDevotion());
            }
        }
    }

    @SpirePatch(
            clz = Nloth.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(Nloth event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int screenNum = ReflectionHacks.getPrivate(event, Nloth.class, "screenNum");
                switch (screenNum) {
                    case 0:
                        switch (buttonPressed) {
                            case 3:
                                event.imageEventText.updateBodyText(DESCRIPTIONS[3]);
                                int maxHpToLose = (int) ((AbstractDungeon.ascensionLevel >= 15 ? 0.15F : 0.1F) * AbstractDungeon.player.maxHealth);
                                AbstractDungeon.player.decreaseMaxHealth(maxHpToLose);
                                AbstractEvent.logMetricObtainCard("N'loth", "Unselfish Devotion", new UnselfishDevotion());
                                AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new UnselfishDevotion(), (float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2)));
                                ReflectionHacks.setPrivate(event, Nloth.class, "screenNum", 1);
                                event.imageEventText.updateDialogOption(0, OPTIONS[2]);
                                event.imageEventText.clearRemainingOptions();
                                return SpireReturn.Return(null);
                        }
                }
            }
            return SpireReturn.Continue();
        }
    }

    static {
        eventStrings = CardCrawlGame.languagePack.getEventString(ID);
        NAME = eventStrings.NAME;
        DESCRIPTIONS = eventStrings.DESCRIPTIONS;
        OPTIONS = eventStrings.OPTIONS;
    }
}
